package jeons.admin.buildproduct.action;

import java.util.List;

import jeons.admin.build.biz.BuildszBiz;
import jeons.admin.build.dto.BuildszDTO;
import jeons.admin.buildproduct.biz.BuildBiz;
import jeons.admin.buildproduct.biz.TestBiz;
import jeons.admin.buildproduct.dto.BuildDTO;
import jeons.admin.buildproduct.dto.BuildQnADTO;
import jeons.admin.buildproduct.dto.TestDTO;
import jeons.admin.product.biz.CpuBiz;
import jeons.admin.product.biz.ProductBiz;
import jeons.admin.product.dto.ProductDTO;
import jeons.admin.product.dto.ProductSerchDTO;
import jeons.buildqna.biz.BuildQnaBiz;
import jeons.common.util.PageDTO;
import jeons.common.util.PagingHelper;

import org.springbyexample.web.servlet.view.tiles2.TilesUrlBasedViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 * @FileName  : BuildProductAction.java
 * @Project     : jeons
 * @Date         : 2012. 1. 24. 
 * @�ۼ���      : Administrator
 * @�����̷� :
 * @���� :
 */
@Controller
@RequestMapping("admin/buildproduct")
public class BuildProductAction {
	@Autowired TilesUrlBasedViewResolver tilesUrlBasedViewResolver;
	@Autowired CpuBiz cpuBiz;
	@Autowired ProductBiz productBiz;
	@Autowired BuildBiz buildBiz;
	@Autowired TestBiz testBiz;
	@Autowired BuildszBiz buildszBiz;
	@Autowired BuildQnaBiz buildQnaBiz;
	
	@RequestMapping(value="/", method=RequestMethod.GET)
	public String index(){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		return "admin/buildproduct/index";
	}
	
	
	@RequestMapping(value="/insert", method=RequestMethod.GET)
	public String insert(Model model){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		model.addAttribute("build",new BuildDTO());
		return "admin/buildproduct/insert";
	}
	
	@RequestMapping(value="/cpu_list", method=RequestMethod.GET)
	public @ResponseBody List<ProductDTO> cpu_list(Model model){
		return productBiz.getTypeList("cpu");
	}
	
	
	@RequestMapping(value="/home_index", method=RequestMethod.GET)
	public String home_index(Model model){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		model.addAttribute("data",buildBiz.getList());
		return "admin/buildproduct/home/home_index";
	}
	
	
	/** 
	* @Method Name  : home_Insert 
	* @�ۼ���   : 2012. 1. 24. 
	* @�ۼ���   : Administrator 
	* @�����̷�  : 
	* @Method ���� : ������
	* @param model
	* @return 
	*/
	@RequestMapping(value="/home_insert", method=RequestMethod.GET)
	public String home_Insert(Model model,PageDTO pageDTO,@ModelAttribute("buildQnADTO")BuildQnADTO buildQnADTO){
		tilesUrlBasedViewResolver.setTilesDefinitionName("admin");
		model.addAttribute("build",new BuildDTO());
		ProductSerchDTO product_cpu_List = new ProductSerchDTO(10000,100000,"cpu");
		model.addAttribute("cpu",productBiz.getSerchTypeList(product_cpu_List));
		
		ProductSerchDTO product_memory_List = new ProductSerchDTO(10000,25000,"memory");
		model.addAttribute("memory",productBiz.getSerchTypeList(product_memory_List));
		
		ProductSerchDTO product_graphic_List = new ProductSerchDTO(10000,80000,"graphic");
		model.addAttribute("graphic",productBiz.getSerchTypeList(product_graphic_List));
		
		
		ProductSerchDTO product_cd_List = new ProductSerchDTO(10000,25000,"cd");
		model.addAttribute("cd",productBiz.getSerchTypeList(product_cd_List));
		
		
		ProductSerchDTO product_hard_List = new ProductSerchDTO(10000,100000,"hard");
		model.addAttribute("hard",productBiz.getSerchTypeList(product_hard_List));
		
		
		ProductSerchDTO product_power_List = new ProductSerchDTO(10000,25000,"power");
		model.addAttribute("power",productBiz.getSerchTypeList(product_power_List));
		
		
		ProductSerchDTO product_mainboard_List = new ProductSerchDTO(10000,76000,"mainboard");
		model.addAttribute("mainboard",productBiz.getSerchTypeList(product_mainboard_List));
		
		ProductSerchDTO product_case_List = new ProductSerchDTO(10000,25000,"case");
		model.addAttribute("case",productBiz.getSerchTypeList(product_case_List));
		
		ProductSerchDTO product_soundnlan_List = new ProductSerchDTO(10000,30000,"soundnlan");
		model.addAttribute("soundnlan",productBiz.getSerchTypeList(product_soundnlan_List));
		
		
		
		return "admin/buildproduct/home/home_insert";
	}
	
	@RequestMapping(value="/home_insert", method=RequestMethod.POST)
	public String home_InsertData(Model model,@ModelAttribute("build")BuildDTO buildDTO) throws Exception{
		buildBiz.insertData(buildDTO);
		/*model.addAttribute("data",buildBiz.getList());*/
		model.addAttribute("data",buildBiz.getList());
		return "admin/buildproduct/home/home_index";
	}
	
	
	
}
